package sanrenxing.dayEnd.backRepertoryTotal.dao;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.PathVariable;
import sanrenxing.dayEnd.backRepertoryTotal.domain.CashAccount;
import sanrenxing.dayEnd.backRepertoryTotal.domain.Foundation;

import java.util.List;
import java.util.Map;

/**
 * 功能：现金账户数据层接口类
 * 编写者：蒋玲苹
 * 日期：
 * 版本：1.0
 */
@Repository
public interface CashAccountDao {
    /**
     * 添加数据
     * @param cashAccount 现金账户对象
     * @return 0:添加失败,1:添加成功
     */
    @Insert("insert into cashAccount values(seqCashAccount.nextval,#{fundId},#{bankCard},#{accName},#{bankName},#{depType},#{cardRate},#{intePer},to_date('${openTime}','yyyy-MM-dd'),to_date('${endTime}','yyyy-MM-dd'))")
    public int add(CashAccount cashAccount);

    /**
     * 删除数据
     * @param caId 现金账户ID
     * @return 删除影响的行数(0:删除失败,1:删除成功)
     */
    @Delete("delete from cashAccount where caId=#{caId}")
    public int delete(@PathVariable("caId") int caId);

    /**
     * 修改数据
     * @param cashAccount 现金账户对象
     * @return 0:修改失败,1:修改成功
     */
    @Update("update cashAccount set bankCard=#{bankCard},accName=#{accName},bankName=#{bankName},depType=#{depType},cardRate=#{cardRate},intePer=#{intePer},openTime=to_date('${openTime}','yyyy-MM-dd'),endTime=to_date('${endTime}','yyyy-MM-dd'),fundId=#{fundId} where caId=#{caId}")
    public int update(CashAccount cashAccount);
    @Select("select * from fundSetup")
    public List<Foundation> fs();
    /**
     * 查询数据
     * @param map 集合
     * @return
     */
    @Select("<script>" +
            "select caId,fundId,bankCard,accName,bankName,depType,cardRate,intePer,to_char(openTime,'yyyy-MM-dd') as openTime,to_char(endTime,'yyyy-MM-dd') as endTime from " +
            " (select rownum rn,cashAccount.* from cashAccount " +
            " <where>#{end}>=rownum</where>)" +
            "<where>" +
            "<if test='cashAccount.accName!=null'>" +
            " and accName like '%${cashAccount.accName}%'" +
            "</if>" +
            "<if test='cashAccount.depType!=0'>" +
            " and depType=#{cashAccount.depType}" +
            "</if>" +
            " and rn>=#{start}" +
            "</where>" +
            "</script>")
   /* @Results({
            @Result(property = "caId",column = "caId"),
            @Result(property = "fundId",column = "fundId"),
            @Result(property = "bankCard",column = "bankCard"),
            @Result(property = "accName",column = "accName"),
            @Result(property = "bankName",column = "bankName"),
            @Result(property = "depType",column = "depType"),
            @Result(property = "cardRate",column = "cardRate"),
            @Result(property = "intePer",column = "intePer"),
            @Result(property = "openTime",column = "openTime"),
            @Result(property = "endTime",column = "endTime"),
    })*/
    public List<CashAccount> qureyAll(Map<String, Object> map);

    /**
     * 统计记录数
     * @param
     * @return 记录行数据
     */
    @Select("select count(*) from cashAccount")
    public int count();

}
